<template>
  <div>
    <!-- 显示类 -->
    <el-table style="width: 100%; margin-top: 50px" border :data="list">
      <el-table-column
        type="index"
        label="序号"
        width="80px"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="buyerId"
        label="账号"
        width="150px"
      ></el-table-column>
      <el-table-column
        prop="buyerName"
        label="用户名"
        width="150px"
      ></el-table-column>
      <el-table-column
        prop="prop"
        label="地址"
        width="width"
      >
      <template slot-scope="{ row }">
            <div class="block">
              <el-carousel
                height="50px"
                :autoplay="false"
                indicator-position="none"
              >
                <el-carousel-item v-for="item in getAddressList(row.buyerAddress)" :key="item">
                  
                  <p>{{item}}</p>
                </el-carousel-item>
              </el-carousel>
            </div> </template
        >
    </el-table-column>
      <el-table-column
        prop="buyerPhone"
        label="电话"
        width="120px"
      ></el-table-column>
      <el-table-column prop="prop" label="操作" width="300px">
        <template slot-scope="{ row }">
          <router-link :to="{name:'OrderForm',params: {buyerId:row.buyerId}}">
          <el-button type="success" icon="el-icon-tickets" 
            >查看订单</el-button
          >
        </router-link>
        <router-link :to="{name:'HistoryOrder',params: {buyerId:row.buyerId}}">
          <el-button type="success" icon="el-icon-tickets" style="margin-left: 10px;"
            >查看历史记录</el-button
          >
        </router-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      style="margin-top: 20px; text-align: center"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="limit"
      layout="sizes, prev, pager, next, total"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "Buyer",

  data() {
    return {
      page: 1,
      limit: 5,
      total: 0,
      list: [],
    };
  },

  mounted() {
    this.getBuyerList();
  },
  methods: {
    handleSizeChange(limit) {
      this.limit = limit;
      this.getBuyerList();
    },
    handleCurrentChange(pager) {
      this.page = pager;
      this.getBuyerList();
    },
    getAddressList(buyerAddress){
      return buyerAddress.split(";");
    },
    //获取所有用户
    async getBuyerList() {
      const { page, limit } = this;
      let result = await this.$API.buyer.reqBuyerList(page, limit);
      if (result.code == 200) {
        this.total = result.data.total;
        this.list = result.data.buyerList;
      } else {
        return Promise.reject(new Error("false"));
      }
    },
    //带着用户账号跳转到订单页面
  },
};
</script>

<style lang="scss" scoped>
</style>